<?php
	function cutString($string,$size,$type=' ...'){
		$string2 = strip_tags($string);
		$string = trim($string);
		$str_str = strlen($string);// Độ dài chuỗi Input + Tag
		$str_str2 = strlen($string2);// Độ dài chuỗi Input + No Tag
		$size = ($str_str-$str_str2)+$size;
		$str = substr($string,$size,20);
		$exp = explode(" ",$str);
		$sum =  count($exp);
		$yes= "";
		for($i=0;$i<=$sum-1;$i++)
		{
			if($yes==""){
				$a = strlen($exp[$i]);
				if($a==0){ $yes="no"; $a=0;}
				if(($a>=1)&&($a<=12)){ $yes = "no"; $a;}
				if($a>12){ $yes = "no"; $a=12;}
			}
		}
		$sub = substr($string,0,$size+$a);
		if($str_str2-$size>0){ $sub.= $type;}
		return $sub;
	}
	
	function rand_string($length) {
		$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
		$size = strlen( $chars );
		$str ='';
		for( $i = 0; $i < $length; $i++ ) {
			$str .= $chars[ rand( 0, $size - 1 ) ];
		}
		return $str;
	}
	
	function rand_num($length) {
		$chars = "0123456789";
		$size = strlen( $chars );
		$str ='';
		for( $i = 0; $i < $length; $i++ ) {
			$str .= $chars[ rand( 0, $size - 1 ) ];
		}
		return $str;
	}
?>